<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <template>
            <a-col :xl="10" :lg="17" :md="8" :sm="24">
              <a-form-item label="推广员用户编号">
                <a-input placeholder="请输入用户编号" v-model="queryParam.userId" @pressEnter="searchQuery"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="17" :md="8" :sm="24">
              <a-form-item label="推广员手机号">
                <a-input placeholder="推广员手机号" v-model="queryParam.phone" @pressEnter="searchQuery"></a-input>
              </a-form-item>
            </a-col>
<!--            <a-col :xl="5" :lg="17" :md="8" :sm="24">-->
<!--              <a-form-item label="备注">-->
<!--                <a-input placeholder="请输入备注" v-model="queryParam.remark" @pressEnter="searchQuery"></a-input>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
          </template>
          <a-col :xl="4" :lg="4" :md="6" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" icon="download"      v-has="'queryuserSalesman:exportXls'"   @click="handleExportXls('推广员导出')">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作栏 end -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <template slot="remark" slot-scope="text, record">
          <a-input style="width: 100px;"
            size="small"
            v-model="record.remark"
            @blur="handleCommonChange(record)"
          />
        </template>
        <template slot="oneRate" slot-scope="text, record">
         <span> <a-input style="width: 100px;"
                         size="small"
                         v-model="record.oneRate"
                         @blur="handleCommonChange(record)"
         />%</span>
        </template>
<!--        <template slot="twoRate" slot-scope="text, record">-->
<!--          <span>  <a-input style="width: 100px;"-->
<!--                           size="small"-->
<!--                           v-model="record.twoRate"-->
<!--                           @blur="handleCommonChange(record)"-->
<!--          />%</span>-->
<!--        </template>-->
        <span slot="action" slot-scope="text, record">
<!--          <a v-if="record.auditStatus != 1" v-has="'agent:btn'" @click="handleEdit(record)">审核</a>-->
<!--          <a-divider type="vertical" />-->
<!--          <a v-has="'agent:particulars'" v-if="record.auditStatus == 1" @click="handlePromotion(record)">推广详情</a>-->
         <a v-has="'agent:particulars'"  @click="handlePromotion(record)">推广用户</a>
          <a-divider type="vertical" />
         <a v-has="'agent:promotionCoach'"  @click="handleCoachPromotion(record)">推广技师</a>

        </span>
        <template slot="avatarUrl" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="record.avatarUrl" />
          </div>
        </template>

        <template slot="auditStatus" slot-scope="text, record">
          <div class="anty-img-wrap">
            <!-- {{ record.auditStatus }} -->
            <a-tag :color="auditStatuss[record.auditStatus].color">
              {{ auditStatuss[record.auditStatus].label }}
            </a-tag>
          </div>
        </template>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <xhdjActivityBalanceCard-modal ref="modalForm" @ok="modalFormOk"></xhdjActivityBalanceCard-modal>
    <XhdjActivityBalanceCarddialog ref="modalDetail" @ok="modalFormOk"></XhdjActivityBalanceCarddialog>
    <QueryuserCoachSalesmanPageDetailModal ref="coachModalDetail" @ok="modalFormOk"></QueryuserCoachSalesmanPageDetailModal>

  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import XhdjActivityBalanceCardModal from './modules/QueryuserSalesmanPageModal'
import XhdjActivityBalanceCarddialog from './modules/QueryuserSalesmanPageDetailModal'
import QueryuserCoachSalesmanPageDetailModal from './modules/QueryuserCoachSalesmanPageDetailModal'

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction } from '@api/manage'

export default {
  name: 'QueryuserSalesmanPageModalList',
  mixins: [JeecgListMixin],
  components: {
    XhdjActivityBalanceCardModal,
    XhdjActivityBalanceCarddialog,
    QueryuserCoachSalesmanPageDetailModal
  },
  data () {
    return {

      auditStatuss: [
        {
          label: '待审核',
          color: 'red'
        },
        {
          label: '已审核',
          color: 'pink'
        },
        {
          label: '驳回',
          color: 'orange'
        }
      ],
      description: '推广员列表页面',

      // 表头
      columns: [
        {
          title: '推广用户编号',
          align: 'center',
          dataIndex: 'userId'
        },
        {
          title: '头像',
          align: 'center',
          dataIndex: 'avatarUrl',
          scopedSlots: { customRender: 'avatarUrl' }
        },
        {
          title: '昵称',
          align: 'center',
          dataIndex: 'nickName'
        },
        // {
        //   title: '审核状态',
        //   align: 'center',
        //   dataIndex: 'auditStatus',
        //   scopedSlots: { customRender: 'auditStatus' }
        // },
        // {
        //   title: '联系人',
        //   align: 'center',
        //   dataIndex: 'name'
        // },
        {
          title: '手机账号',
          align: 'center',
          dataIndex: 'phone'
        },
        // {
        //   title: ' 是否有资源',
        //   align: 'center',
        //   dataIndex: 'isResource',
        //   customRender: (text, record) => {
        //     return record.isResource == 0 ? '有' : '无'
        //   }
        // },
        // {
        //   title: ' 推广区域',
        //   align: 'center',
        //   dataIndex: 'cityName'
        // },
        // {
        //   title: '备注',
        //   align: 'center',
        //   dataIndex: 'remark',
        //   scopedSlots: { customRender: 'remark' }
        // },
        {
          title: '佣金余额',
          align: 'center',
          dataIndex: 'commissionAmount'
        },
        // {
        //   title: '独自一级返佣',
        //   align: 'center',
        //   dataIndex: 'oneRate',
        //   scopedSlots: { customRender: 'oneRate' }
        // },
        // {
        //   title: '独自二级返佣',
        //   align: 'center',
        //   dataIndex: 'twoRate',
        //   scopedSlots: { customRender: 'twoRate' }
        // },
        {
          title: '直推邀请用户数',
          align: 'center',
          dataIndex: 'stairNumber'
        },
        {
          title: '推荐技师数',
          align: 'center',
          dataIndex: 'coachNumber'
        },
        // {
        //   title: '二级邀请用户数',
        //   align: 'center',
        //   dataIndex: 'teamNumber'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 80,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/user/xhdjUserSalesman/queryUserSalesmanPageList',
        update: '/user/xhdjUserSalesman/edit',
        exportXlsUrl: '/user/xhdjUserSalesman/queryUserSalesmanexportXls',
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    handleZS (record) {
      this.$refs.dialogForm.edit(record)
      this.$refs.dialogForm.title = '赠送'
      this.$refs.dialogForm.disableSubmit = false
    },
    handleCommonChange(record){
      let data = {
        id: record.id,
        remark: record.remark
      }
      httpAction(this.url.update, record, 'post').then(res => {
        if (res.success) {
          this.loadData()
        }
      })
    },
    handlePromotion (record) {
      this.$refs.modalDetail.edit(record)
      this.$refs.modalDetail.title = '推广详情'
      this.$refs.modalDetail.disableSubmit = false
    },
    handleCoachPromotion (record) {
      this.$refs.coachModalDetail.edit(record)
      this.$refs.coachModalDetail.title = '推广详情'
      this.$refs.coachModalDetail.disableSubmit = false
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
</style>
